﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Windows;
using ThePresenter.Data.Presentation.Polls;
using ThePresenter.ViewModel;

namespace ThePresenter.Data.Presentation
{
	[Serializable]
	public sealed class Presentation : ViewModelBase, ISerializable
	{
		#region Fields

		string _title;

		string _author;

		readonly DateTime _dateOfCreation;

		Size _initialSize;

		SlideCollection _slides;

		Slide _selectedSlide;

		#endregion

		#region Properties

		public string Title
		{
			get
			{
				return _title;
			}
			set
			{
				if (_title != value)
				{
					_title = value;
					OnPropertyChanged("Title");
				}
			}
		}

		public string Author
		{
			get
			{
				return _author;
			}
			set
			{
				if (_author != value)
				{
					_author = value;
					OnPropertyChanged("Author");
				}
			}
		}

		public DateTime DateOfCreation
		{
			get
			{
				return _dateOfCreation;
			}
		}

		public Size InitialSize
		{
			get
			{
				return _initialSize;
			}
		}

		public SlideCollection Slides
		{
			get
			{
				return _slides;
			}
		}

		public Slide SelectedSlide
		{
			get
			{
				return _selectedSlide;
			}
			set
			{
				if (_selectedSlide != value)
				{
					_selectedSlide = value;
					SelectSlide(value);
					OnPropertyChanged("SelectedSlide");
				}
			}
		}

		IEnumerable<Poll> Polls
		{
			get
			{
				return Slides.SelectMany(i => i.Polls);
			}
		}

		#endregion

		/// <summary>
		/// Initializes a new instance of the <see cref="Presentation"/> class.
		/// </summary>
		/// <param name="initialSize">The initial size.</param>
		public Presentation(Size initialSize)
		{
			_initialSize = initialSize;
			_dateOfCreation = DateTime.Now;
			_slides = new SlideCollection();
		}

		#region Methods

		private void SelectSlide(Slide value)
		{
			throw new NotImplementedException();
		}

		#endregion

		#region ISerializable Members

		/// <summary>
		/// Initializes a new instance of the <see cref="Presentation"/> class.
		/// </summary>
		/// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data.</param>
		/// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination. .</param>
		public Presentation(SerializationInfo info, StreamingContext context)
		{
			// ...
		}

		/// <summary>
		/// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data.</param>
		/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param>
		/// <exception cref="T:System.Security.SecurityException">
		/// The caller does not have the required permission.
		/// </exception>
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			// ...
		}

		#endregion
	}
}
